import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.Timer;

import javax.swing.JPanel;


@SuppressWarnings("serial")
public class PanelClass extends JPanel implements ActionListener {
	
	double x =0.0;
	double y = 0.0;
	Timer t;
	
	MainThing c;
	
	public PanelClass(JFrame f){
		
		c = new MainThing();
		t = new Timer(10, this);
		this.setBackground(Color.gray);
		t.addActionListener(c);
		f.addKeyListener(c);
		t.start();
	}
	
	public boolean speed1;
	public boolean speed2;
	public boolean win1;
	public boolean win2;
	public static String name1;
	public static String name2;
	
	@Override
	public void paint(Graphics g){
		Graphics2D g2d = (Graphics2D)g;
		super.paint(g2d);
		win1 = c.getWin1();
		win2 = c.getWin2();
		g2d.setColor(Color.black);
		g2d.setFont(new Font("font3", Font.PLAIN, 100));
		if(win1){
			t.stop();
			g2d.drawString("Winner!", 350, 500);
		}
		if(win2){
			g2d.drawString("Winner!", 350, 200);
			t.stop();
		}
		g2d.setColor(c.getColor());
		g2d.fill(c.getP1());
		g2d.fill(c.getP2());
		if(!win1 && !win2){
			g2d.fill(c.getCircle());
		}
		g2d.setColor(Color.darkGray);
		g2d.fillRect(0, 0, 75, 1024);		//walls
		g2d.fillRect(943, 0, 75, 1024);		//
		g2d.fillRect(0, 642, 200, 50);		//
		g2d.fillRect(818, 642, 200, 50);	//
		g2d.fillRect(0, 0, 200, 50);		//
		g2d.fillRect(818, 0, 200, 50);		//walls
		g2d.setFont(new Font("font1", Font.BOLD, 50));
		g2d.setColor(Color.white);
		g2d.drawString(c.getScoreP1(), 85, 685);
		g2d.drawString(c.getScoreP2(), 85, 45);
		g2d.setFont(new Font("font4", Font.PLAIN, 35));
		g2d.drawString(name1, 825, 680);
		g2d.drawString(name2, 825, 40);
		g2d.setFont(new Font("font2", Font.PLAIN, 14));
		speed1 = c.getSpeedP1();
		speed2 = c.getSpeedP2();
		if(speed1){
			g2d.drawString("Speed: Yes", 8, 685);
		}else{
			g2d.drawString("Speed: No", 8, 685);
		}
		if(speed2){
			g2d.drawString("Speed: Yes", 8, 43);
		}else{
			g2d.drawString("Speed: No", 8, 43);
		}
		win1 = c.getWin1();
		win2 = c.getWin2();
		g2d.setColor(Color.black);
		g2d.setFont(new Font("font3", Font.PLAIN, 100));
	}
	
	public void actionPerformed(ActionEvent e){
		if(e.getSource().equals(t)){
			x += 1;
			y += 1;
			this.repaint();
		}
	}
	
	public static void main(String[]args){
		name1 = JOptionPane.showInputDialog("Enter the name of player1.");
		name2 = JOptionPane.showInputDialog("Enter the name of player2.");
		JFrame frame = new JFrame("Ultra Pong");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(1024, 720);
		frame.setResizable(false);
		PanelClass pc = new PanelClass(frame);
		frame.add(pc);
		frame.setVisible(true);
	}
}
